package com.hyg.lib_music.ui.activity;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;

import android.os.Bundle;
import android.util.Log;
import android.view.View;

import com.hyg.lib_base.mainUtils.StatusBarUtil;
import com.hyg.lib_common.Base.BaseActivity;
import com.hyg.lib_common.DataUtil.UserSPUtils;
import com.hyg.lib_music.R;
import com.hyg.lib_music.adapter.ClockSetttingsAdapter;
import com.hyg.lib_music.databinding.ActivityClockSettingBinding;
import com.hyg.lib_music.modle.ClockData;
import com.lljjcoder.widget.RecycleViewDividerForList;

import java.util.ArrayList;

public class ClockSettingActivity extends BaseActivity {
    ArrayList<ClockData> list = new ArrayList<>();

    ActivityClockSettingBinding binding;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = ActivityClockSettingBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());
        init();
    }

    public void init() {
        StatusBarUtil.setStatusBar(3, this, getResources().getColor(R.color.white), 60, null, null, true);
        binding.lnTitleView.back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        binding.lnTitleView.tvTitle.setText("定时关闭");
        initData();
    }

    public void initData() {
        long startTime = UserSPUtils.getMusicClockStartTime(this);
        long min = UserSPUtils.getMusicClockSettingMin(this);
        long cuttentTime = System.currentTimeMillis();
        if (cuttentTime - startTime > min * 15 * 60 * 1000) {
            list.add(new ClockData("不开启", true));
            list.add(new ClockData("15分钟后", false));
            list.add(new ClockData("30分钟后", false));
            list.add(new ClockData("45分钟后", false));
            list.add(new ClockData("60分钟后", false));
        } else {
            switch ((int) min) {
                case 1:
                    list.add(new ClockData("不开启", false));
                    list.add(new ClockData("15分钟后", true));
                    list.add(new ClockData("30分钟后", false));
                    list.add(new ClockData("45分钟后", false));
                    list.add(new ClockData("60分钟后", false));
                    break;
                case 2:
                    list.add(new ClockData("不开启", false));
                    list.add(new ClockData("15分钟后", false));
                    list.add(new ClockData("30分钟后", true));
                    list.add(new ClockData("45分钟后", false));
                    list.add(new ClockData("60分钟后", false));
                    break;
                case 3:
                    list.add(new ClockData("不开启", false));
                    list.add(new ClockData("15分钟后", false));
                    list.add(new ClockData("30分钟后", false));
                    list.add(new ClockData("45分钟后", true));
                    list.add(new ClockData("60分钟后", false));
                    break;
                case 4:
                    list.add(new ClockData("不开启", false));
                    list.add(new ClockData("15分钟后", false));
                    list.add(new ClockData("30分钟后", false));
                    list.add(new ClockData("45分钟后", false));
                    list.add(new ClockData("60分钟后", true));
                    break;
                default:
                    list.add(new ClockData("不开启", true));
                    list.add(new ClockData("15分钟后", false));
                    list.add(new ClockData("30分钟后", false));
                    list.add(new ClockData("45分钟后", false));
                    list.add(new ClockData("60分钟后", false));
                    break;
            }
        }
        LinearLayoutManager layoutManager = new LinearLayoutManager(ClockSettingActivity.this);
        binding.rcvClockSetttings.setLayoutManager(layoutManager);
        ClockSetttingsAdapter adapter = new ClockSetttingsAdapter(ClockSettingActivity.this, list);
        binding.rcvClockSetttings.addItemDecoration(new RecycleViewDividerForList(
                ClockSettingActivity.this, LinearLayoutManager.VERTICAL, 10, getResources().getColor(R.color.musicTextHint)));
        binding.rcvClockSetttings.setAdapter(adapter);
    }

}